package com.qf.controller;

import com.qf.pojo.req.UserReq;
import com.qf.pojo.resp.BaseResp;
import com.qf.pojo.vo.Address;
import com.qf.pojo.vo.User;
import com.qf.service.UserService;
import com.qf.utils.UploadToken;
import com.qf.utils.UplodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("login")
    public BaseResp login(@RequestBody UserReq user) {
        return userService.login(user);
    }

    @RequestMapping("/sendphone")
    public BaseResp sendphone(@RequestBody Map map) {
        return userService.sendphone(map.get("phone").toString());
    }

    //通过手机号查询某个用户
    @RequestMapping("/findone")
    public BaseResp findone(@RequestBody Map map) {
        //System.out.println();
        return userService.findone(map.get("phone").toString());
    }

    @RequestMapping("/gettoken")
    public String gettoken() {
        String upload = UploadToken.upload();
        return upload;
    }
    @RequestMapping("/updateinformation")
    public BaseResp updateinformation(@RequestBody User user){
        return userService.updateinformation(user);
    }
    @RequestMapping("/findaddress")
    public BaseResp findAddress(@RequestBody Map map){
        return userService.findAddress(Integer.valueOf(map.get("uid").toString()));
    }
    //修改用户收货地址
    @RequestMapping("/addORupdate")
    public BaseResp addORupdate(@RequestBody Address address){
        System.out.println(address.getX1());
        System.out.println(address.getY1());
        return userService.addORupdate(address);
    }
    //删除用户地址
    @RequestMapping("/deleteAddess")
    public BaseResp deleteAddess(@RequestBody Map map){
        return userService.deleteAddess(Integer.valueOf(map.get("id").toString()));
    }
    @RequestMapping("/token")
    public String gettoken(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        return null;

    }
}
